<!-- This comment will put IE 6, 7 and 8 in quirks mode -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>eCommerce: Plik źródłowy D:/CentrumXP/e-Commerce/eCommerceDev/SklepDAO/VideoDAO.cs</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javaScript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<!-- Wygenerowano przez Doxygen 1.6.1 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Szukaj');
--></script>
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Strona&nbsp;główna</span></a></li>
      <li><a href="namespaces.html"><span>Pakiety</span></a></li>
      <li><a href="annotated.html"><span>Klasy</span></a></li>
      <li class="current"><a href="files.html"><span>Pliki</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <img id="MSearchSelect" src="search/search.png"
             onmouseover="return searchBox.OnSearchSelectShow()"
             onmouseout="return searchBox.OnSearchSelectHide()"
             alt=""/>
        <input type="text" id="MSearchField" value="Szukaj" accesskey="S"
             onfocus="searchBox.OnSearchFieldFocus(true)" 
             onblur="searchBox.OnSearchFieldFocus(false)" 
             onkeyup="searchBox.OnSearchFieldChange(event)"/>
        <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
        </div>
      </li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>Lista&nbsp;plików</span></a></li>
      <li><a href="globals.html"><span>Składowe&nbsp;plików</span></a></li>
    </ul>
  </div>
<h1>D:/CentrumXP/e-Commerce/eCommerceDev/SklepDAO/VideoDAO.cs</h1><a href="_video_d_a_o_8cs.html">Idź do dokumentacji tego pliku.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a><a class="code" href="_video_d_a_o_8cs.html#a81a223a02c34d82b47199f08308847f2">00001</a> ﻿using <a class="code" href="_common_tools_8cs.html#a81a223a02c34d82b47199f08308847f2">System</a>;
<a name="l00002"></a>00002 <span class="keyword">using</span> <a class="code" href="_common_tools_8cs.html#a81a223a02c34d82b47199f08308847f2">System</a>.Collections.Generic;
<a name="l00003"></a>00003 <span class="keyword">using</span> <a class="code" href="_common_tools_8cs.html#a81a223a02c34d82b47199f08308847f2">System</a>.Data.SqlClient;
<a name="l00004"></a>00004 <span class="keyword">using</span> <a class="code" href="_common_tools_8cs.html#a81a223a02c34d82b47199f08308847f2">System</a>.Data;
<a name="l00005"></a>00005 <span class="keyword">using</span> <a class="code" href="_common_tools_8cs.html#a81a223a02c34d82b47199f08308847f2">System</a>.Text;
<a name="l00006"></a>00006 
<a name="l00007"></a>00007 <span class="keyword">using</span> ShopModel;
<a name="l00008"></a>00008 
<a name="l00009"></a>00009 <span class="keyword">namespace </span>ShopDAO
<a name="l00010"></a>00010 {
<a name="l00011"></a><a class="code" href="class_shop_d_a_o_1_1_video_d_a_o.html">00011</a>     <span class="keyword">public</span> <span class="keyword">class </span><a class="code" href="class_shop_d_a_o_1_1_video_d_a_o.html">VideoDAO</a>
<a name="l00012"></a>00012     {
<a name="l00013"></a>00013         <span class="keyword">private</span> <span class="keywordtype">string</span> connectionString;
<a name="l00014"></a>00014 
<a name="l00015"></a><a class="code" href="class_shop_d_a_o_1_1_video_d_a_o.html#aff44b9da78af3db059b129d79ec99a21">00015</a>         <span class="keyword">public</span> <a class="code" href="class_shop_d_a_o_1_1_video_d_a_o.html#aff44b9da78af3db059b129d79ec99a21">VideoDAO</a>()
<a name="l00016"></a>00016         {
<a name="l00017"></a>00017             connectionString = <a class="code" href="_common_tools_8cs.html#a81a223a02c34d82b47199f08308847f2">System</a>.Configuration.ConfigurationManager.ConnectionStrings[<span class="stringliteral">&quot;csShop&quot;</span>].ConnectionString;
<a name="l00018"></a>00018         }
<a name="l00019"></a>00019 
<a name="l00032"></a><a class="code" href="class_shop_d_a_o_1_1_video_d_a_o.html#a1b0899c982a881d70dc51da7d66ae53a">00032</a>         <span class="keyword">public</span>  <span class="keywordtype">bool</span> <a class="code" href="class_shop_d_a_o_1_1_video_d_a_o.html#a1b0899c982a881d70dc51da7d66ae53a" title="Zapisuje informacje o pliku video do bazy. (Saves information about the video file...">SaveVideo</a>(<a class="code" href="class_shop_model_1_1_video_info.html" title="Klasa przechowuje informacje o materiałach video opisujących konkretny produkt...">VideoInfo</a> Video)
<a name="l00033"></a>00033         {
<a name="l00034"></a>00034             SqlConnection connection = <span class="keyword">new</span> SqlConnection(connectionString);
<a name="l00035"></a>00035             SqlCommand sqlCommand = connection.CreateCommand();
<a name="l00036"></a>00036 
<a name="l00037"></a>00037             sqlCommand.CommandText = <span class="stringliteral">&quot;SaveVideo&quot;</span>;
<a name="l00038"></a>00038             sqlCommand.CommandType = <a class="code" href="_common_tools_8cs.html#a81a223a02c34d82b47199f08308847f2">System</a>.Data.CommandType.StoredProcedure;
<a name="l00039"></a>00039 
<a name="l00040"></a>00040             sqlCommand.Parameters.Add(<span class="keyword">new</span> SqlParameter(<span class="stringliteral">&quot;@FileName&quot;</span>, Video.<a class="code" href="class_shop_model_1_1_video_info.html#a9464b3fed95e56c63ee6a89ba7cd08af">FileName</a>));
<a name="l00041"></a>00041             sqlCommand.Parameters.Add(<span class="keyword">new</span> SqlParameter(<span class="stringliteral">&quot;@ProductID&quot;</span>, Video.<a class="code" href="class_shop_model_1_1_video_info.html#a4fb077c7756e2c209f955f6f1e782cd0">ProductID</a>));
<a name="l00042"></a>00042             sqlCommand.Parameters.Add(<span class="keyword">new</span> SqlParameter(<span class="stringliteral">&quot;@Label&quot;</span>, Video.<a class="code" href="class_shop_model_1_1_video_info.html#adfe886fd3acbedb85991936daff8b367">Label</a>));
<a name="l00043"></a>00043 
<a name="l00044"></a>00044 
<a name="l00045"></a>00045             <span class="keywordflow">try</span>
<a name="l00046"></a>00046             {
<a name="l00047"></a>00047                 connection.Open();
<a name="l00048"></a>00048                 <span class="keywordflow">return</span> sqlCommand.ExecuteNonQuery() &gt; 0;
<a name="l00049"></a>00049             }
<a name="l00050"></a>00050             <span class="keywordflow">catch</span> (Exception ex)
<a name="l00051"></a>00051             {
<a name="l00052"></a>00052                 ErrorLogger.LogError(ex);
<a name="l00053"></a>00053                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00054"></a>00054             }
<a name="l00055"></a>00055             <span class="keywordflow">finally</span>
<a name="l00056"></a>00056             {
<a name="l00057"></a>00057                 connection.Close();
<a name="l00058"></a>00058             }
<a name="l00059"></a>00059         }
<a name="l00060"></a>00060 
<a name="l00073"></a><a class="code" href="class_shop_d_a_o_1_1_video_d_a_o.html#a47e21d26e5e564cdad6ebf867f6f851c">00073</a>         <span class="keyword">public</span>  List&lt;VideoInfo&gt; <a class="code" href="class_shop_d_a_o_1_1_video_d_a_o.html#a47e21d26e5e564cdad6ebf867f6f851c" title="Pobiera listę filmów dla danego produktu. (Downloads list of movies for the given...">GetVideos</a>(<span class="keywordtype">int</span> ProductID)
<a name="l00074"></a>00074         {
<a name="l00075"></a>00075             SqlConnection sqlC = <span class="keyword">new</span> SqlConnection(connectionString);
<a name="l00076"></a>00076             SqlCommand command = sqlC.CreateCommand();
<a name="l00077"></a>00077             SqlDataReader sqlR;
<a name="l00078"></a>00078 
<a name="l00079"></a>00079             List&lt;VideoInfo&gt; result = <span class="keyword">new</span> List&lt;VideoInfo&gt;();
<a name="l00080"></a>00080 
<a name="l00081"></a>00081             command.CommandText = <span class="stringliteral">&quot;GetVideos&quot;</span>;
<a name="l00082"></a>00082             command.CommandType = CommandType.StoredProcedure;
<a name="l00083"></a>00083 
<a name="l00084"></a>00084             command.Parameters.Add(<span class="keyword">new</span> SqlParameter(<span class="stringliteral">&quot;@ProductID&quot;</span>, ProductID));
<a name="l00085"></a>00085 
<a name="l00086"></a>00086             <span class="keywordflow">try</span>
<a name="l00087"></a>00087             {
<a name="l00088"></a>00088                 sqlC.Open();
<a name="l00089"></a>00089                 sqlR = command.ExecuteReader();
<a name="l00090"></a>00090 
<a name="l00091"></a>00091                 <span class="keywordflow">while</span> (sqlR.Read())
<a name="l00092"></a>00092                 {
<a name="l00093"></a>00093                     result.Add(<span class="keyword">new</span> <a class="code" href="class_shop_model_1_1_video_info.html" title="Klasa przechowuje informacje o materiałach video opisujących konkretny produkt...">VideoInfo</a>((<span class="keywordtype">int</span>)sqlR[<span class="stringliteral">&quot;IDVideo&quot;</span>], (<span class="keywordtype">int</span>)sqlR[<span class="stringliteral">&quot;ProductID&quot;</span>], (<span class="keywordtype">string</span>)sqlR[<span class="stringliteral">&quot;FileName&quot;</span>], (<span class="keywordtype">string</span>)sqlR[<span class="stringliteral">&quot;Label&quot;</span>]));
<a name="l00094"></a>00094                 }
<a name="l00095"></a>00095                 sqlR.Close();
<a name="l00096"></a>00096             }
<a name="l00097"></a>00097             <span class="keywordflow">catch</span> (Exception ex)
<a name="l00098"></a>00098             {
<a name="l00099"></a>00099                 ErrorLogger.LogError(ex);
<a name="l00100"></a>00100                 <span class="keywordflow">return</span> null;
<a name="l00101"></a>00101             }
<a name="l00102"></a>00102             <span class="keywordflow">finally</span>
<a name="l00103"></a>00103             {
<a name="l00104"></a>00104                 sqlC.Close();
<a name="l00105"></a>00105             }
<a name="l00106"></a>00106 
<a name="l00107"></a>00107             <span class="keywordflow">return</span> result;
<a name="l00108"></a>00108         }
<a name="l00109"></a>00109 
<a name="l00122"></a><a class="code" href="class_shop_d_a_o_1_1_video_d_a_o.html#abbbcb9fdeaa5fbe67d7461a0e8719e9f">00122</a>         <span class="keyword">public</span>  <span class="keywordtype">bool</span> <a class="code" href="class_shop_d_a_o_1_1_video_d_a_o.html#abbbcb9fdeaa5fbe67d7461a0e8719e9f" title="Usuwa informacje o wybranym pliku video z bazy. (Removes information about the selected...">DeleteVideo</a>(<span class="keywordtype">int</span> VideoID)
<a name="l00123"></a>00123         {
<a name="l00124"></a>00124             SqlConnection connection = <span class="keyword">new</span> SqlConnection(connectionString);
<a name="l00125"></a>00125             SqlCommand sqlCommand = connection.CreateCommand();
<a name="l00126"></a>00126 
<a name="l00127"></a>00127             sqlCommand.CommandText = <span class="stringliteral">&quot;DeleteVideo&quot;</span>;
<a name="l00128"></a>00128             sqlCommand.CommandType = <a class="code" href="_common_tools_8cs.html#a81a223a02c34d82b47199f08308847f2">System</a>.Data.CommandType.StoredProcedure;
<a name="l00129"></a>00129 
<a name="l00130"></a>00130             sqlCommand.Parameters.Add(<span class="keyword">new</span> SqlParameter(<span class="stringliteral">&quot;@VideoID&quot;</span>, VideoID));
<a name="l00131"></a>00131 
<a name="l00132"></a>00132             <span class="keywordflow">try</span>
<a name="l00133"></a>00133             {
<a name="l00134"></a>00134                 connection.Open();
<a name="l00135"></a>00135                 <span class="keywordflow">return</span> (<span class="keywordtype">int</span>)sqlCommand.ExecuteScalar() &gt; 0;
<a name="l00136"></a>00136             }
<a name="l00137"></a>00137             <span class="keywordflow">catch</span> (Exception ex)
<a name="l00138"></a>00138             {
<a name="l00139"></a>00139                 ErrorLogger.LogError(ex);
<a name="l00140"></a>00140                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00141"></a>00141             }
<a name="l00142"></a>00142             <span class="keywordflow">finally</span>
<a name="l00143"></a>00143             {
<a name="l00144"></a>00144                 connection.Close();
<a name="l00145"></a>00145             }
<a name="l00146"></a>00146         }
<a name="l00147"></a>00147 
<a name="l00160"></a><a class="code" href="class_shop_d_a_o_1_1_video_d_a_o.html#af7d10633ebedbaad2334a53a3665304c">00160</a>         <span class="keyword">public</span> <a class="code" href="class_shop_model_1_1_video_info.html" title="Klasa przechowuje informacje o materiałach video opisujących konkretny produkt...">VideoInfo</a> <a class="code" href="class_shop_d_a_o_1_1_video_d_a_o.html#af7d10633ebedbaad2334a53a3665304c" title="Pobiera informacje o wybranym pliku video. (Retrieves information about the selected...">GetVideo</a>(<span class="keywordtype">int</span> VideoID)
<a name="l00161"></a>00161         {
<a name="l00162"></a>00162             SqlConnection sqlC = <span class="keyword">new</span> SqlConnection(connectionString);
<a name="l00163"></a>00163             SqlCommand command = sqlC.CreateCommand();
<a name="l00164"></a>00164             SqlDataReader sqlR;
<a name="l00165"></a>00165 
<a name="l00166"></a>00166             <a class="code" href="class_shop_model_1_1_video_info.html" title="Klasa przechowuje informacje o materiałach video opisujących konkretny produkt...">VideoInfo</a> result = null;
<a name="l00167"></a>00167 
<a name="l00168"></a>00168             command.CommandText = <span class="stringliteral">&quot;GetVideos&quot;</span>;
<a name="l00169"></a>00169             command.CommandType = CommandType.StoredProcedure;
<a name="l00170"></a>00170 
<a name="l00171"></a>00171             command.Parameters.Add(<span class="keyword">new</span> SqlParameter(<span class="stringliteral">&quot;@VideoID&quot;</span>, VideoID));
<a name="l00172"></a>00172 
<a name="l00173"></a>00173             <span class="keywordflow">try</span>
<a name="l00174"></a>00174             {
<a name="l00175"></a>00175                 sqlC.Open();
<a name="l00176"></a>00176                 sqlR = command.ExecuteReader();
<a name="l00177"></a>00177 
<a name="l00178"></a>00178                 <span class="keywordflow">if</span> (sqlR.Read())
<a name="l00179"></a>00179                     result = <span class="keyword">new</span> <a class="code" href="class_shop_model_1_1_video_info.html" title="Klasa przechowuje informacje o materiałach video opisujących konkretny produkt...">VideoInfo</a>((<span class="keywordtype">int</span>)sqlR[<span class="stringliteral">&quot;IDVideo&quot;</span>], (int)sqlR[<span class="stringliteral">&quot;ProductID&quot;</span>], (<span class="keywordtype">string</span>)sqlR[<span class="stringliteral">&quot;FileName&quot;</span>], (string)sqlR[<span class="stringliteral">&quot;Label&quot;</span>]);
<a name="l00180"></a>00180                 
<a name="l00181"></a>00181                 sqlR.Close();
<a name="l00182"></a>00182             }
<a name="l00183"></a>00183             <span class="keywordflow">catch</span> (Exception ex)
<a name="l00184"></a>00184             {
<a name="l00185"></a>00185                 ErrorLogger.LogError(ex);
<a name="l00186"></a>00186                 <span class="keywordflow">return</span> null;
<a name="l00187"></a>00187             }
<a name="l00188"></a>00188             <span class="keywordflow">finally</span>
<a name="l00189"></a>00189             {
<a name="l00190"></a>00190                 sqlC.Close();
<a name="l00191"></a>00191             }
<a name="l00192"></a>00192 
<a name="l00193"></a>00193             <span class="keywordflow">return</span> result;
<a name="l00194"></a>00194         }
<a name="l00195"></a>00195 
<a name="l00201"></a><a class="code" href="class_shop_d_a_o_1_1_video_d_a_o.html#aec3ccffbadd7d46a4cce100408b6ac16">00201</a>         <span class="keyword">public</span> <span class="keywordtype">bool</span> <a class="code" href="class_shop_d_a_o_1_1_video_d_a_o.html#aec3ccffbadd7d46a4cce100408b6ac16" title="Removes video’s files from the database.">DeleteVideoFromDataBase</a>(<span class="keywordtype">int</span> productID)
<a name="l00202"></a>00202         {
<a name="l00203"></a>00203             SqlConnection connection = <span class="keyword">new</span> SqlConnection(connectionString);
<a name="l00204"></a>00204             SqlCommand sqlCommand = connection.CreateCommand();
<a name="l00205"></a>00205 
<a name="l00206"></a>00206 
<a name="l00207"></a>00207 
<a name="l00208"></a>00208             sqlCommand.CommandText = <span class="stringliteral">&quot;DeleteVideoFromDataBase&quot;</span>;
<a name="l00209"></a>00209             sqlCommand.CommandType = <a class="code" href="_common_tools_8cs.html#a81a223a02c34d82b47199f08308847f2">System</a>.Data.CommandType.StoredProcedure;
<a name="l00210"></a>00210             sqlCommand.Parameters.Add(<span class="keyword">new</span> SqlParameter(<span class="stringliteral">&quot;@productID&quot;</span>, productID));
<a name="l00211"></a>00211             <span class="keywordflow">try</span>
<a name="l00212"></a>00212             {
<a name="l00213"></a>00213                 connection.Open();
<a name="l00214"></a>00214                 sqlCommand.ExecuteNonQuery();
<a name="l00215"></a>00215                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00216"></a>00216             }
<a name="l00217"></a>00217             <span class="keywordflow">catch</span> (Exception ex)
<a name="l00218"></a>00218             {
<a name="l00219"></a>00219                 ErrorLogger.LogError(ex);
<a name="l00220"></a>00220                 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00221"></a>00221             }
<a name="l00222"></a>00222             <span class="keywordflow">finally</span>
<a name="l00223"></a>00223             {
<a name="l00224"></a>00224                 connection.Close();
<a name="l00225"></a>00225             }
<a name="l00226"></a>00226 
<a name="l00227"></a>00227         }
<a name="l00228"></a>00228     }
<a name="l00229"></a>00229 }
</pre></div></div>
<!--- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&nbsp;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&nbsp;</span>Klasy</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&nbsp;</span>Przestrzenie nazw</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&nbsp;</span>Pliki</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&nbsp;</span>Funkcje</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&nbsp;</span>Zmienne</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&nbsp;</span>Wyliczenia</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&nbsp;</span>Właściwości</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&nbsp;</span>Zdarzenia</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<hr size="1"/><address style="text-align: right;"><small>Wygenerowano Mon Nov 9 06:08:18 2009 dla eCommerce programem&nbsp;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.1 </small></address>
</body>
</html>
